#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/statvfs.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <pthread.h>
#include <sched.h>
#include <ctype.h>
#include <malloc.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <linux/if.h>

#define DF_FILE  "/tmp/df.txt"

struct df_info {
    char * file_system;
    char * size;
    char * used;
    char * available;
    char * use_percent;
    char * mounted;
};

int xy_usb_detect_mount(void)
{
    FILE * fp;
    char buf[1024] = {0};
    int i = 0;
    char * line = NULL;
    size_t len = 0;
    size_t read = 0;
    struct df_info info;

    if (!system("df -h > /tmp/df.txt")) {
        if ((fp = fopen(DF_FILE, "r")) == NULL) {
            printf("%s failed to open.\n", (char *)DF_FILE);
            return -1;
        }

        info.size = "512M";
        printf("%s\n", info.size);

        while (fgets(buf, sizeof buf, fp)) {
            memset(&info, 0, sizeof(struct df_info));

            sscanf(buf, "%s %s %s %s %s %s", info.file_system, info.size,
                             info.used, info.available, info.use_percent, info.mounted);

            printf("%s   %s   %s   %s   %s   %s\n", info.file_system, info.size,
                           info.used, info.available, info.use_percent, info.mounted);
        }

        fclose(fp);
    }

    return 0;
}

void main()
{
    xy_usb_detect_mount();
}
